
package controllers;

import models.User;
import play.db.jpa.Transactional;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.index;

public class Application extends Controller {

    public static User getUser() {
        String id = session("user");
        models.security.Token token = models.security.Token.manager.get(id);

        User result = token.getUser();
        return result;
    }

    public static void setUser(final User user) {
        if (user == null || user.isEmpty()) {
            String id = session("user");
            models.security.Token.manager.delete(id);
            session("user", "");
        } else {
            models.security.Token token = models.security.Token.manager.create(user);
            session("user", token.getId().toString());
        }
    }

    @Transactional
    public static Result index() {
        return ok(index.render(""));
    }

    @Transactional
    public static Result about() {    	
        return ok(views.html.help.about.render(""));
    }

}